package cn.xiaomubiao.oschine.fragment;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.xiaomubiao.oschine.R;
import cn.xiaomubiao.oschine.base.BaseNavFragment;
import cn.xiaomubiao.oschine.viewpagerfragment.tweetspagerfragment.HotTweet;
import cn.xiaomubiao.oschine.viewpagerfragment.tweetspagerfragment.MyTweet;
import cn.xiaomubiao.oschine.viewpagerfragment.tweetspagerfragment.NewestTweet;

/**
 * Created by hasee on 2017/4/1.
 * 动弹页面
 */

public class TweetsViewPagerFragment extends BaseNavFragment {
    @BindView(R.id.tablayout_tweets)
    TabLayout mTabLayout;
    @BindView(R.id.viewpager_tweets)
    ViewPager mViewpager;

    private String[] tabTexts = {"最新动弹", "热门动弹", "我的动弹"};
    private Fragment[] tweetsFragments = {new NewestTweet(), new HotTweet(), new MyTweet()};

    @Override
    public View initView() {
        View rootView = View.inflate(mActivity, R.layout.view_tweets_fragment, null);
        ButterKnife.bind(this, rootView);
        return rootView;
    }


    @Override
    public void initData() {
        mViewpager.setAdapter(new tweetsPagerAdapter(getChildFragmentManager()));
        mTabLayout.setupWithViewPager(mViewpager);
    }

    class tweetsPagerAdapter extends FragmentStatePagerAdapter {

        public tweetsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return tweetsFragments[position];
        }

        @Override
        public int getCount() {
            return tabTexts.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return tabTexts[position];
        }
    }

}
